use strict;
use warnings;

package JasPerl::JSTL::Core::ParamTag;
use parent qw(JasPerl::TagExt::JspBodyTag);

use JasPerl::Exceptions;

my $PARENT_CLASS = 'JasPerl::JSTL::Core::ParamParent';

sub set_name {
    $_[0]->{name} = $_[1];
}

sub set_value {
    $_[0]->{value} = $_[1];
}

sub do_tag {
    my $self = shift;
    my $parent = $self->find_ancestor_isa($PARENT_CLASS)
        or JasPerl::JSTL::Core::IllegalParentTagException->throw('param');
    if (exists $self->{value}) {
        $parent->add_parameter($self->{name}, $self->{value});
    } else {
        $parent->add_parameter($self->{name}, $self->get_body_content());
    }
}

1;
